﻿using PhuLeBooze.UICode;
using PhuLeBussinessObject.Base;
using PhuLeBussinessObject.Site;
using PhuLeDao.Site;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace PhuLeBooze.Administrator.Views.Home
{
    public partial class ConfigSite : System.Web.UI.Page
    {
        CSiteDao siteDao = new CSiteDao();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                IList<CConfigSite> list = siteDao.GetConfigSite("<InputValue Context=\"GetSiteConfig\" />");
                if (list != null)
                {
                    txtCompanyName.Text = list[0].CompanyName;
                    txtAddress.Text = list[0].Address;
                    txtPhone.Text = list[0].Phone;
                    txtEmail.Text = list[0].Email;
                    txtCopyright.Text = list[0].Copyright;
                    txtEmailForward.Text = list[0].EmailForward;
                    txtContactPurchases.Text = list[0].ContactPurchases;
                    
                }
            }
            ltrInfo.Text = "";
        }

        protected void btnUpdate_Click(object sender, EventArgs e)
        {
            try
            {

                string compnayName = Server.HtmlEncode(txtCompanyName.Text.Trim());
                string address = Server.HtmlEncode(txtAddress.Text.Trim());
                string phone = Server.HtmlEncode(txtPhone.Text.Trim());
                string email = Server.HtmlEncode(txtEmail.Text.Trim());
                string copyRight = Server.HtmlEncode(txtCopyright.Text.Trim());
                string emailForward = Server.HtmlEncode(txtEmailForward.Text.Trim());
                string contactPurchases = Server.HtmlEncode(txtContactPurchases.Text.Trim());
                CApplicationMessage a = siteDao.ActionConfigSite(string.Format("<InputValue CompanyName=\"{0}\"  Address=\"{1}\"  Phone=\"{2}\"  Email=\"{3}\"   Copyright=\"{4}\"   EmailForward=\"{5}\" ContactPurchases=\"{6}\"  Action=\"Insert\"/>", compnayName, address, phone, email, copyRight, emailForward, contactPurchases));
                CConfigSiteEntity.ReadConfig();
            }
            catch (Exception ex) {
                ltrInfo.Text = ex.ToString();
            }
            ltrInfo.Text = "Cập nhật thành công";
        }
    }
}